/******************************************************************************
**
** Copyright 2011 Motorola Solutions Inc. All rights reserved.
**
** File name: 	utimer.c
**
** Description:	Timer-counter functionality related to RTOS Unit
**				Tests execution. Targets supported:
**				- ATXmega32D4 (HW)
**
** Change history:
**	
** 11/20/2011 - AK - File created. 
** 
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "utimer.h"

/*
**
**	UTST_TIMER_t	usr_tmr	=
**		{
**			&TCC0,
**			555,
**			LEVEL_LO,
**			STATE_RUN
**		};
**	utst_init_timer( &usr_tmr );
**
*/
void utst_init_timer(UTST_TIMER_t * tmr) 
{
	tmr->addr->CTRLA = ( tmr->addr->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_OFF_gc;
	tmr->addr->CNT = 0;
	tmr->addr->PER = tmr->period;
	//tmr->addr->INTCTRLA = ( tmr->addr->INTCTRLA & ~TC0_OVFINTLVL_gm ) | TC_OVFINTLVL_LO_gc ;
	tmr->addr->INTCTRLA = ( tmr->addr->INTCTRLA & ~TC0_OVFINTLVL_gm ) | tmr->level;
	if ( tmr->state == STATE_RUN )
	{
		tmr->addr->CTRLA = ( tmr->addr->CTRLA & ~TC0_CLKSEL_gm ) | TC_CLKSEL_DIV8_gc;
	}
}


